package leetcode.editor.cn;

import java.util.HashSet;
import java.util.Set;

/**
 * 2554. 从一个范围内选择最多整数 I
 */
public class Solution2554 {
    public int maxCount(int[] banned, int n, int maxSum) {
        Set<Integer> bannedSet = new HashSet<>();
        for (int ban : banned) {
            bannedSet.add(ban);
        }
        int res = 0;
        for (int i = 1; i <= n; i++) {
            if (i>maxSum) {
                break;
            }
            if (bannedSet.contains(i)){
                continue;
            }
            maxSum -= i;
            res++;
        }
        return res;
    }
}
